<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="用户名" prop="username"
                :rules="[
                  {required: true, message:'用户名不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.username" placeholder="请填写用户名"     ></el-input>
           </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
            <el-form-item label="用户" prop="userinformation.id"
                :rules="[
                  {required: true, message:'用户不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择用户"
            labelName = 'userName'
            labelValue = 'id'
            :value = "inputForm.userinformation.id"
            :limit="1"
            @getValue='(value) => {inputForm.userinformation.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            dataListUrl="/dlyrl/hr/userinformation/userInformation/list"
            entityBeanName="userInformation"
            queryEntityUrl="/dlyrl/hr/userinformation/userInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="服务公司" prop="enterpriseInformation.id"
                :rules="[
                  {required: true, message:'服务公司不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择服务公司"
            labelName = 'companyName'
            labelValue = 'id'
            :value = "inputForm.enterpriseInformation.id"
            :limit="1"
            @getValue='(value) => {inputForm.enterpriseInformation.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'companyName',
              label: '企业名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'companyName',
              label: '企业名称'
            }
            ]"
            dataListUrl="/dlyrl/hr/enterpriseinformation/enterpriseInformation/list"
            entityBeanName="enterpriseInformation"
            queryEntityUrl="/dlyrl/hr/enterpriseinformation/enterpriseInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="身份证号" prop="idNumber"
                :rules="[
                  {required: true, message:'身份证号不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.idNumber" placeholder="请填写身份证号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="部门" prop="department.id"
                :rules="[
                  {required: true, message:'部门不能为空', trigger:'blur'}
                 ]">
          <SelectTree
                      ref="department"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/dlyrl/hr/orporateinstitutions/orporateInstitutions/treeData"
                      :value="inputForm.department.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.department.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="岗位" prop="job"
                :rules="[
                  {required: true, message:'岗位不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.job" placeholder="请填写岗位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="基本工资" prop="basePay"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basePay" placeholder="请填写基本工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="岗位工资" prop="postWage"
                :rules="[
                 ]">
              <el-input v-model="inputForm.postWage" placeholder="请填写岗位工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="绩效工资" prop="meritPay"
                :rules="[
                 ]">
              <el-input v-model="inputForm.meritPay" placeholder="请填写绩效工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="基本合计" prop="combinedBasic"
                :rules="[
                 ]">
              <el-input v-model="inputForm.combinedBasic" placeholder="请填写基本合计"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工龄工资" prop="seniorityPay"
                :rules="[
                 ]">
              <el-input v-model="inputForm.seniorityPay" placeholder="请填写工龄工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="餐费补助" prop="mealAllowance"
                :rules="[
                 ]">
              <el-input v-model="inputForm.mealAllowance" placeholder="请填写餐费补助"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="交通补助" prop="trafficAllowance"
                :rules="[
                 ]">
              <el-input v-model="inputForm.trafficAllowance" placeholder="请填写交通补助"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="业务提成" prop="commission"
                :rules="[
                 ]">
              <el-input v-model="inputForm.commission" placeholder="请填写业务提成"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="出差补助" prop="travelAllowance"
                :rules="[
                 ]">
              <el-input v-model="inputForm.travelAllowance" placeholder="请填写出差补助"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="全勤奖" prop="attendanceBonus"
                :rules="[
                 ]">
              <el-input v-model="inputForm.attendanceBonus" placeholder="请填写全勤奖"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="加班费" prop="overtime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.overtime" placeholder="请填写加班费"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="通信补助" prop="communicateSubsidy"
                :rules="[
                 ]">
              <el-input v-model="inputForm.communicateSubsidy" placeholder="请填写通信补助"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="其他补助" prop="otherSupport"
                :rules="[
                 ]">
              <el-input v-model="inputForm.otherSupport" placeholder="请填写其他补助"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="福利待遇合计" prop="totalWelfareBenefits"
                :rules="[
                 ]">
              <el-input v-model="inputForm.totalWelfareBenefits" placeholder="请填写福利待遇合计"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="应出勤天数" prop="shouldAttendanceDay"
                :rules="[
                 ]">
              <el-input v-model="inputForm.shouldAttendanceDay" placeholder="请填写应出勤天数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="出差天数" prop="travelDays"
                :rules="[
                 ]">
              <el-input v-model="inputForm.travelDays" placeholder="请填写出差天数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="请假天数" prop="leaveDays"
                :rules="[
                 ]">
              <el-input v-model="inputForm.leaveDays" placeholder="请填写请假天数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="实际出勤天数" prop="realityAttendanceDay"
                :rules="[
                 ]">
              <el-input v-model="inputForm.realityAttendanceDay" placeholder="请填写实际出勤天数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="应发工资" prop="shouldsalary"
                :rules="[
                 ]">
              <el-input v-model="inputForm.shouldsalary" placeholder="请填写应发工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="基本养老" prop="basicOldAgePension"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basicOldAgePension" placeholder="请填写基本养老"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="基本医疗" prop="basicMedicalCare"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basicMedicalCare" placeholder="请填写基本医疗"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="失业保险" prop="unemploymentInsurance"
                :rules="[
                 ]">
              <el-input v-model="inputForm.unemploymentInsurance" placeholder="请填写失业保险"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="住房公积金" prop="housingProvidentFund"
                :rules="[
                 ]">
              <el-input v-model="inputForm.housingProvidentFund" placeholder="请填写住房公积金"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="个人所得税" prop="individualIncomeTax"
                :rules="[
                 ]">
              <el-input v-model="inputForm.individualIncomeTax" placeholder="请填写个人所得税"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="其他扣款" prop="otherDeductions"
                :rules="[
                 ]">
              <el-input v-model="inputForm.otherDeductions" placeholder="请填写其他扣款"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="扣款合计" prop="deductionsCombined"
                :rules="[
                 ]">
              <el-input v-model="inputForm.deductionsCombined" placeholder="请填写扣款合计"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="实发工资" prop="netPayroll"
                :rules="[
                 ]">
              <el-input v-model="inputForm.netPayroll" placeholder="请填写实发工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="部门id" prop="office"
                :rules="[
                 ]">
              <el-input v-model="inputForm.office" placeholder="请填写部门id"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="底薪" prop="baseSalary"
                :rules="[
                 ]">
              <el-input v-model="inputForm.baseSalary" placeholder="请填写底薪"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="社保基数" prop="socialSecurityBase"
                :rules="[
                 ]">
              <el-input v-model="inputForm.socialSecurityBase" placeholder="请填写社保基数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="请假扣款" prop="leaveForDeduction"
                :rules="[
                 ]">
              <el-input v-model="inputForm.leaveForDeduction" placeholder="请填写请假扣款"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工资时间、月份" prop="salYear"
                :rules="[
                 ]">
              <el-input v-model="inputForm.salYear" placeholder="请填写工资时间、月份"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="审批人" prop="approver"
                :rules="[
                 ]">
              <el-input v-model="inputForm.approver" placeholder="请填写审批人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="日期" prop="payrollTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.payrollTime" placeholder="请填写日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="手机号" prop="phone"
                :rules="[
                  {required: true, message:'手机号不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.phone" placeholder="请填写手机号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="迟到扣款" prop="lately"
                :rules="[
                 ]">
              <el-input v-model="inputForm.lately" placeholder="请填写迟到扣款"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="早退扣款" prop="leaveearly"
                :rules="[
                 ]">
              <el-input v-model="inputForm.leaveearly" placeholder="请填写早退扣款"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="旷工扣款" prop="absenteeism"
                :rules="[
                 ]">
              <el-input v-model="inputForm.absenteeism" placeholder="请填写旷工扣款"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="年终工资" prop="endSalary"
                :rules="[
                 ]">
              <el-input v-model="inputForm.endSalary" placeholder="请填写年终工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="年终应发工资" prop="endBaseSal"
                :rules="[
                 ]">
              <el-input v-model="inputForm.endBaseSal" placeholder="请填写年终应发工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          username: '',
          userinformation: {
            id: ''
          },
          enterpriseInformation: {
            id: ''
          },
          idNumber: '',
          department: {
            id: ''
          },
          job: '',
          basePay: '',
          postWage: '',
          meritPay: '',
          combinedBasic: '',
          seniorityPay: '',
          mealAllowance: '',
          trafficAllowance: '',
          commission: '',
          travelAllowance: '',
          attendanceBonus: '',
          overtime: '',
          communicateSubsidy: '',
          otherSupport: '',
          totalWelfareBenefits: '',
          shouldAttendanceDay: '',
          travelDays: '',
          remarks: '',
          leaveDays: '',
          realityAttendanceDay: '',
          shouldsalary: '',
          basicOldAgePension: '',
          basicMedicalCare: '',
          unemploymentInsurance: '',
          housingProvidentFund: '',
          individualIncomeTax: '',
          otherDeductions: '',
          deductionsCombined: '',
          netPayroll: '',
          office: '',
          baseSalary: '',
          socialSecurityBase: '',
          leaveForDeduction: '',
          salYear: '',
          approver: '',
          payrollTime: '',
          phone: '',
          lately: '',
          leaveearly: '',
          absenteeism: '',
          endSalary: '',
          endBaseSal: ''
        }
      }
    },
    components: {
      GridSelect,
      SelectTree
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建工资表`
        } else if (method === 'edit') {
          this.title = '修改工资表'
        } else if (method === 'view') {
          this.title = '查看工资表'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/dlyrl/hr/salary/salary/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.salary)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/dlyrl/hr/salary/salary/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>